package com.longsunhd.yum.buffalo;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.EditText;
import android.widget.Spinner;

import com.longsunhd.yum.buffalo.util.GlobalClient;
import com.longsunhd.yum.buffalo.util.ToastUtils;
import com.gg.reader.api.protocol.gx.EnumG;
import com.gg.reader.api.protocol.gx.MsgBaseStop;
import com.gg.reader.api.protocol.gx.MsgTestCarrierWave;
import com.gg.reader.api.protocol.gx.MsgTestVSWRcheck;

import java.util.Hashtable;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class TestActivity extends AppCompatActivity {

    @BindView(R.id.freq_point)
    Spinner freq_point;

    @BindView(R.id.standing_wave_pre)
    EditText standing_wave_pre;

    @BindView(R.id.standing_wave_suf)
    EditText standing_wave_suf;


    private Hashtable<Integer, Integer> mAntMap = new Hashtable<Integer, Integer>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.test);
        ButterKnife.bind(this);

    }

    @OnClick(R.id.standing_wave_send)
    public void standing_wave_send() {
        MsgTestCarrierWave wave = new MsgTestCarrierWave();
        wave.setAntennaNum(EnumG.AntennaNo_1);
        wave.setFreqCursor(freq_point.getSelectedItemPosition());
        GlobalClient.getClient().sendSynMsg(wave);
        if (wave.getRtCode() == 0) {
            ToastUtils.showText(wave.getRtMsg());
        } else {
            ToastUtils.showText(wave.getRtMsg());
        }
    }

    @OnClick(R.id.standing_wave_stop)
    public void standing_wave_stop() {
        MsgBaseStop stop = new MsgBaseStop();
        GlobalClient.getClient().sendSynMsg(stop);
        if (stop.getRtCode() == 0) {
            ToastUtils.showText("载波已关闭");
        } else {
            ToastUtils.showText(stop.getRtMsg());
        }
    }

    @OnClick(R.id.detection)
    public void detection() {
        MsgTestVSWRcheck msg = new MsgTestVSWRcheck();
        GlobalClient.getClient().sendSynMsg(msg);
        if (msg.getRtCode() == 0) {
            standing_wave_pre.setText(msg.getPreValue() + "");
            standing_wave_suf.setText(msg.getSufValue() + "");
        } else {
            ToastUtils.showText(msg.getRtMsg());
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        standing_wave_stop();
    }
}
